package cn.stl.basic.service.impl;

import cn.stl.basic.mapper.BaseMapper;
import cn.stl.basic.query.BaseQuery;
import cn.stl.basic.service.BaseService;
import cn.stl.basic.util.PageList;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
@Transactional(readOnly = true,propagation = Propagation.SUPPORTS)
public class BaseServiceImplM<T> implements BaseService<T> {
    @Autowired
    private BaseMapper<T> baseMapper;

    @Override
    @Transactional
    public void save(T t) {
        baseMapper.save(t);
    }

    @Override
    @Transactional
    public void remove(Long id) {
        baseMapper.remove(id);
    }

    @Override
    @Transactional
    public void update(T t) {
        baseMapper.update(t);
    }

    @Override
    public T loadById(Long id) {
        return  baseMapper.loadById(id);
    }

    @Override
    public List<T> loadAll() {

        return baseMapper.loadAll();
    }
    //分页
    @Override
    public PageList<T> queryData(BaseQuery baseQuery) {
        Long count = baseMapper.queryCount(baseQuery);
        if (count == 0){
            return new PageList<>();
        }
        List<T> rows = baseMapper.queryData(baseQuery);
        PageList<T> pageList = new PageList<>(count, rows);
        return pageList;
    }

    @Override
    @Transactional
    public void patchDelete(List<Long> ids) {
        baseMapper.patchDelete(ids);
    }

}
